<%--
  Created by IntelliJ IDEA.
  User: 862982795
  Date: 2021/07/01
  Time: 21:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加疫苗接种预约信息</title>

    <script type="text/javascript" src="js/jquery-1.12.4.js"></script>

    <script type="text/javascript">
        $("#b1").click(function () {

            //预约人姓名
            var name = $(".name").val();
            if (name === "" || name == null) {
                alert("请填写完整的信息！");
                return;
            }

            //身份证号
            var cardId = $(".cardId").val();
            if (cardId === "" || cardId == null) {
                alert("请填写完整的信息！");
                return;
            }

            //预约日期
            var date = $(".date").val();
            var dateFormat = /^(\d{4})-(\d{2})-(\d{2})$/;
            if (date === "" || date == null) {
                alert("请填写完整的信息！");
                return;
            }

            if (!dateFormat.test(date)) {
                alert("日期格式不正确！");
                return;
            }

            $.get("QueryCardId", "cardId=" + cardId, callBack);

            //响应成功
            function callBack(data) {
                alert(data);
                if (data === "true") {
                    $("span").html("<br>该人员已接种或预约接种疫苗!");
                    alert('进来if');

                } else {

                    $("span").html("");
                    $("form").submit();
                }
            }

        });

        function inspect() {
            //预约人姓名
            var name = $(".name").val();
            if (name === "" || name == null) {
                alert("请填写完整的信息！");
                return;
            }

            //身份证号
            var cardId = $(".cardId").val();
            if (name === "" || name == null) {
                alert("请填写完整的信息！");
                return;
            }

            //预约日期
            var date = $(".date").val();
            var dateFormat = /^(\d{4})-(\d{2})-(\d{2})$/;
            if (date === "" || date == null) {
                alert("请填写完整的信息！");
                return;
            }

            if (!dateFormat.test(date)) {
                alert("日期格式不正确！");
                return;
            }

            $.get("CheckCardIdServlet", "cardId=" + cardId, callBack);

            //响应成功
            function callBack(data) {
                if (data === "true") {
                    $("span").html("<br>该人员已接种或预约接种疫苗!");

                } else {
                    $("span").html("");
                    $("form").submit();
                }
            }
        }
    </script>

</head>
<body>


<div align="center">

    <form action="AddServlet" method="get">

        <table border="1" cellspacing="0">

            <caption>添加疫苗接种预约信息</caption>

            <tr>
                <td>预约人姓名(*)</td>
                <td><input type="text" name="name" class="name" value=""></td>
            </tr>
            <tr>
                <td>预约人身份证号(*)</td>
                <td><input type="text" name="cardId" class="cardId"><span
                        style="font-size: 70%"></span></td>
            </tr>
            <tr>
                <td>预约接种日期(*)</td>
                <td><input type="text" name="date" class="date"></td>
            </tr>
            <tr>
                <td colspan="2" align="center"><input type="button"
                                                      onclick="inspect();" id="b1" value="提交"></td>
            </tr>
        </table>
    </form>
</div>

</body>
</html>
